/*    */ package com.zimbra.cs.imap;
/*    */ 
/*    */ import java.io.IOException;
/*    */ import java.util.List;
/*    */ import org.apache.mina.filter.codec.ProtocolDecoderException;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ final class NioImapRequest
/*    */   extends ImapRequest
/*    */ {
/*    */   private Literal literal;
/*    */   private int literalCount;
/*    */   private boolean complete;
/*    */   
/*    */   NioImapRequest(ImapHandler handler)
/*    */   {
/* 30 */     super(handler);
/*    */   }
/*    */   
/*    */   boolean parse(Object obj) throws IOException, ProtocolDecoderException {
/* 34 */     if (this.literal != null) {
/* 35 */       parseLiteral((byte[])obj);
/*    */     } else {
/* 37 */       parseCommand((String)obj);
/*    */     }
/* 39 */     return this.complete;
/*    */   }
/*    */   
/*    */   private void parseLiteral(byte[] b) throws IOException {
/* 43 */     assert (b.length <= this.literalCount);
/* 44 */     this.literalCount -= this.literal.put(b, 0, b.length);
/* 45 */     if (this.literalCount <= 0) {
/* 46 */       assert (this.literal.remaining() == 0);
/* 47 */       addPart(this.literal);
/* 48 */       this.literal = null;
/*    */     }
/*    */   }
/*    */   
/*    */   private void parseCommand(String line) throws IOException, ProtocolDecoderException {
/* 53 */     addPart(line);
/* 54 */     LiteralInfo li = LiteralInfo.parse(line);
/* 55 */     if (li != null) {
/* 56 */       this.literalCount = li.getCount();
/* 57 */       this.literal = Literal.newInstance(this.literalCount, isAppend());
/* 58 */       if (li.count <= 0) {
/* 59 */         addPart(this.literal);
/* 60 */         this.complete = true;
/* 61 */       } else if (li.isBlocking()) {
/* 62 */         this.mHandler.sendContinuation("send literal data");
/*    */       }
/*    */     } else {
/* 65 */       this.complete = true;
/*    */     }
/*    */   }
/*    */   
/*    */   public Literal readLiteral() throws ImapParseException
/*    */   {
/* 71 */     skipChar('{');
/* 72 */     if (this.index + 1 >= this.parts.size()) {
/* 73 */       throw new ImapParseException(this.tag, "no next literal");
/*    */     }
/* 75 */     ImapRequest.Part part = (ImapRequest.Part)this.parts.get(this.index + 1);
/* 76 */     this.index += 2;
/* 77 */     this.offset = 0;
/* 78 */     return part.getLiteral();
/*    */   }
/*    */   
/*    */   public String toString()
/*    */   {
/* 83 */     StringBuilder sb = new StringBuilder();
/* 84 */     for (ImapRequest.Part part : this.parts) {
/* 85 */       sb.append(part);
/* 86 */       if (part.isString()) {
/* 87 */         sb.append("\r\n");
/*    */       }
/*    */     }
/* 90 */     return sb.toString();
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/imap/NioImapRequest.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */